Skip to main content

Overview

Duet provides two execution environments: the shared terminal workspace and isolated Cloudflare Sandboxes. Sandboxes allow you to run commands in a secure, ephemeral container without affecting your main workspace.

Why sandboxes?

Sandboxes are useful for:

Testing dangerous commands

Try commands like rm -rf without risking your workspace

AI command execution

Let the AI run commands in isolation and show you the output

Quick experiments

Test shell scripts or one-liners without cluttering your workspace

Parallel execution

Run commands concurrently while continuing work in the main terminal

Running commands in a sandbox

Press Ctrl+R to execute a command in the sandbox:
1

Open sandbox input

Press Ctrl+R in the terminal. You’ll see:
2

Enter your command

Type any shell command:
3

View the result

A toast notification appears with the output:
Press Esc to cancel without executing.
Sandbox execution requires a Cloudflare Worker URL, just like the AI assistant:

Architecture

Sandboxes are powered by Cloudflare’s Browser Rendering service:

Per-room sandboxes

Each room gets its own persistent sandbox instance:
This means:
  • Files created in the sandbox persist across commands (within the same session)
  • Each room’s sandbox is completely isolated from others
  • When the room ends, the sandbox is destroyed

Command execution flow

1

Client sends request

The Go client makes an HTTP POST to the Worker:
2

Worker validates input

The Worker uses Zod for schema validation:
3

Sandbox executes command

Cloudflare runs the command in an isolated container and captures stdout/stderr.
4

Result returned to client

Response format

Sandbox execution returns both stdout and stderr:
The client displays whichever is available:

AI integration

The AI assistant automatically uses sandboxes when it includes <run> tags:

Example

When you ask the AI:
The AI responds:
The command runs in the sandbox, and you can verify it worked:
Files created in the sandbox are NOT accessible from your shared terminal. Sandboxes and the terminal workspace are completely separate environments.

API endpoint

endpoint
Execute a command in the room’s sandboxRequest body:
Success response:
Error response:

Cleanup

When a room ends, the sandbox is automatically destroyed:
This happens when:
  1. The last participant leaves the room
  2. The Go server calls DELETE /api/rooms/:roomId
  3. The Worker destroys the sandbox and clears AI state
Cleanup is best-effort. If the Worker is unreachable, Cloudflare will eventually garbage-collect idle sandboxes.

Limitations

Sandboxes are designed for short commands. Long-running processes may be terminated:
Sandboxes have a restricted filesystem with minimal tools. Advanced utilities may not be available.
Sandboxes cannot make outbound network requests:
CPU and memory are constrained. Intensive operations may be throttled or killed.

Error handling

The command doesn’t exist in the sandbox environment.

Comparison: Sandbox vs Terminal

Best practices

Use for experiments

Test unfamiliar commands in the sandbox before running in the terminal

Check output length

Sandbox output is truncated to 500 characters. For long output, use the terminal.

Don't rely on state

Sandboxes are destroyed when the room ends. Use the terminal for persistent work.

Verify AI commands

Always review AI-generated commands before manually running them in your terminal.

Next steps

AI assistant

Learn how the AI uses sandboxes for command execution

Deploy a Worker

Set up Cloudflare Worker and Sandbox bindings